import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import '../models/psychological_test.dart';
import 'test_question_screen.dart';
import 'test_history_screen.dart';

class PsychologicalTestScreen extends StatelessWidget {
  const PsychologicalTestScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey[50],
      appBar: AppBar(
        backgroundColor: Colors.white,
        elevation: 0,
        leading: IconButton(
          icon: const Icon(Icons.arrow_back_ios, color: Colors.black),
          onPressed: () => Navigator.of(context).pop(),
        ),
        title: Text(
          '心理测试',
          style: GoogleFonts.zcoolKuaiLe(
            fontSize: 20,
            fontWeight: FontWeight.bold,
            color: Colors.black,
          ),
        ),
        centerTitle: true,
      ),
      body: SingleChildScrollView(
        child: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              // Text(
              //   '了解自己的心理健康状态',
              //   style: GoogleFonts.maShanZheng(
              //     fontSize: 16,
              //     color: Colors.grey[600],
              //   ),
              //   textAlign: TextAlign.center,
              // ),
              const SizedBox(height: 16),
              // SDS测试卡片
              _buildTestCard(
                context: context,
                title: '抑郁自评量表 (SDS)',
                duration: '约8分钟',
                description: '评估抑郁症状的严重程度，包含20个问题',
                color: Colors.blue,
                onTap: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(
                      builder: (context) => const TestQuestionScreen(
                        testType: TestType.SDS,
                      ),
                    ),
                  );
                },
              ),
              const SizedBox(height: 16),
              // SAS测试卡片
              _buildTestCard(
                context: context,
                title: '焦虑自评量表 (SAS)',
                duration: '约8分钟',
                description: '评估焦虑症状的严重程度，包含20个问题',
                color: Colors.purple,
                onTap: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(
                      builder: (context) => const TestQuestionScreen(
                        testType: TestType.SAS,
                      ),
                    ),
                  );
                },
              ),
              const SizedBox(height: 16),
              // SCL-90测试卡片
              _buildTestCard(
                context: context,
                title: '症状自评量表 (SCL-90)',
                duration: '约15分钟',
                description: '全面评估心理症状，包含90个问题，涵盖9个维度',
                color: Colors.orange,
                onTap: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(
                      builder: (context) => const TestQuestionScreen(
                        testType: TestType.SCL90,
                      ),
                    ),
                  );
                },
              ),
            ],
          ),
        ),
      ),
    );
  }

  Widget _buildTestCard({
    required BuildContext context,
    required String title,
    required String duration,
    required String description,
    required Color color,
    required VoidCallback onTap,
  }) {
    TestType testType = title.contains('SDS') 
        ? TestType.SDS 
        : title.contains('SAS') 
            ? TestType.SAS 
            : TestType.SCL90;

    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(12),
        border: Border.all(color: Colors.grey.shade200),
      ),
      child: Padding(
        padding: const EdgeInsets.all(16),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              children: [
                Expanded(
                  child: Text(
                    title,
                    style: GoogleFonts.zcoolKuaiLe(
                      fontSize: 18,
                      fontWeight: FontWeight.bold,
                      color: Colors.black87,
                    ),
                  ),
                ),
                Icon(
                  title.contains('SDS') ? Icons.sentiment_dissatisfied 
                  : title.contains('SAS') ? Icons.warning_amber
                  : Icons.psychology,
                  size: 20,
                  color: color,
                ),
              ],
            ),
            const SizedBox(height: 8),
            Container(
              padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
              decoration: BoxDecoration(
                color: color.withOpacity(0.1),
                borderRadius: BorderRadius.circular(4),
              ),
              child: Text(
                duration,
                style: GoogleFonts.zcoolKuaiLe(
                  fontSize: 14,
                  color: color,
                ),
              ),
            ),
            const SizedBox(height: 8),
            Text(
              description,
              style: GoogleFonts.zcoolKuaiLe(
                fontSize: 14,
                color: Colors.grey[600],
              ),
            ),
            const SizedBox(height: 16),
            Row(
              children: [
                Expanded(
                  child: ElevatedButton(
                    onPressed: onTap,
                    style: ElevatedButton.styleFrom(
                      backgroundColor: color,
                      foregroundColor: Colors.white,
                      padding: const EdgeInsets.symmetric(vertical: 12),
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(25),
                      ),
                      elevation: 0,
                    ),
                    child: Text(
                      '开始测试',
                      style: GoogleFonts.zcoolKuaiLe(
                        fontSize: 16,
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                  ),
                ),
                const SizedBox(width: 12),
                Expanded(
                  child: OutlinedButton.icon(
                    onPressed: () {
                      Navigator.push(
                        context,
                        MaterialPageRoute(
                          builder: (context) => TestHistoryScreen(testType: testType),
                        ),
                      );
                    },
                    icon: const Icon(Icons.history, size: 18),
                    label: Text(
                      '历史报告',
                      style: GoogleFonts.zcoolKuaiLe(
                        fontSize: 16,
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                    style: OutlinedButton.styleFrom(
                      foregroundColor: color,
                      side: BorderSide(color: color),
                      padding: const EdgeInsets.symmetric(vertical: 12),
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(25),
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
} 